<script type="text/javascript"><!--//--><![CDATA[//><!--

	var grid_reload = function(){
		$('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
	};

	$(document).ready(function() {
		// Setup Datagrid
		$('#datagrid').datagrid({  
			url:gs_path+'/'+controller+'/getdata', 
			queryParams: $('#fm_search').serializeObject(),
			height:340,
			pagination:true,
			columns:[[ //edit nanti
				{ field : 'ck', checkbox:true, width: 40, align: 'center' },				
				{ field : 'kode_mitra', title : 'Kode Mitra', width:200, sortable:true },	
				{ field : 'nama_mitra', title : 'Nama Mitra', width:200, sortable:true },	
				{ field : 'nama_pemilik', title : 'Nama Pemilik', width:200, sortable:true },	
				{ field : 'no_kontrak', title : 'Nomor Kontrak', width:200, sortable:true },				
				{ field : 'tanggal_kontrak', title : 'Tanggal Kotrak', width:170, sortable:true }			
			]]
		});
		
		$('#filter_app_id').setCombo({ data: <?php echo json_encode($arr_application); ?> });
		/*
		// Setup Form
		$('#form_master').setupForm([
			{ name: 'kode_mitra', type:'text', size: 'medium', noempty:true },
			{ name: 'nama_mitra', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'alamat_lengkap', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'no_telp', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'no_fax', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'jenis_usaha', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'jenis_produk', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'npwp', type: 'text', size: 'medium', maxlength: 100, noempty:true },
			{ name: 'website', type: 'text', size: 'medium', maxlength: 100, noempty:true },
			{ name: 'email', type: 'text', size: 'medium', maxlength: 100, noempty:true },

			{ name: 'kode_pemilik', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'nama_pemilik', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'alamat_pemilik', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'no_telp_pemilik', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'no_hand_pemilik', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'no_fax_pemilik', type: 'text', size: 'medium', maxlength: 100, noempty:true },
			{ name: 'website_pemilik', type: 'text', size: 'medium', maxlength: 100, noempty:true },
			{ name: 'email_pemilik', type: 'text', size: 'medium', maxlength: 100, noempty:true },

			{ name: 'no_kontrak', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'tanggal_kontrak', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'awal_kerja', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'akhir_kerja', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'fee_mitra', type: 'text', size: 'medium', maxlength: 100, noempty:true },
			{ name: 'biaya_katalog', type: 'text', size: 'medium', maxlength: 100, noempty:true },

			{ name: 'no_rekening', type: 'text', size: 'medium', maxlength: 10, noempty:true },
			{ name: 'nama_bank', type: 'text', size: 'medium', maxlength: 100, noempty:true },
			{ name: 'atas_nama', type: 'text', size: 'medium', maxlength: 100, noempty:true }
		]);
		
		
		// Create Dialog
		$('#dialog_container').dialog({
			closed:true,
			modal:true,
			title: '_',
			width:900,
			height:730,
			buttons:[{
				text:'Save',
				iconCls:'icon-save',
				handler:function(){
					$('#form_master').submitForm('/'+controller+'/ajax_post', { onComplete : function(){ $('#dialog_container').dialog('close'); $('#datagrid').datagrid('reload'); }} );
				}
			},{
				text:'Close',
				iconCls:'icon-cancel',
				handler:function(){
					$('#dialog_container').dialog('close');
				}
			}]
		});
		*/
		
		// Set Action Button
		var buttons = [ // ----- >> Add Button
                        { label: 'Add', icon: 'add', onclick: function() {
                            var oSel = $('#datagrid').datagrid('getSelected'); 
                            
                            var $popup = openPopup({ title: '&nbsp;', 
                                width: 564,
                                height: 460,
                                url: gs_path + '/' + controller + '/create/' + (oSel == null ? '' : '?kode_mitra=' + oSel.kode_mitra),
                                buttons: [{
                                    text: 'Save',
                                    iconCls: 'icon-save',
                                    handler: function() {
                                        $('#form_popup').submitForm('/' + controller + '/ajax_post', { onComplete: function() { closePopup(); $('#datagrid').datagrid('reload'); } });
                                    }
                                }, {
                                    text: 'Close',
                                    iconCls: 'icon-cancel',
                                    handler: function() {
                                        closePopup();
                                    }
                                }],
                                onComplete: function(){ $('#form_popup').data('mode', 'create'); }
                             });
                            
                        }},

                         // ----- >> Edit Button
					    { label: 'Edit', icon: 'edit', onclick: function() {
					        var oSel = $('#datagrid').datagrid('getSelected');
					        if (oSel == null) {
					            alert('Please select row!'); 
					        } else {

					            var $popup = openPopup({ title: '&nbsp;',
					                width: 564,
					                height: 460,
					                url: gs_path + '/' + controller + '/edit/?kode_mitra=' + urlencode(oSel.kode_mitra),
					                buttons: [{
					                    text: 'Save',
					                    iconCls: 'icon-save',
					                    handler: function() {
					                        $('#form_popup').submitForm('/' + controller + '/ajax_post', { onComplete: function() { closePopup(); $('#datagrid').datagrid('reload'); } });
					                    }
					                }, {
					                    text: 'Close',
					                    iconCls: 'icon-cancel',
					                    handler: function() {
					                        closePopup();
					                    }
                                    }],
					                    onComplete: function() { $('#form_popup').data('mode', 'edit'); }
					            });
					        } 
					    }},

					    // ----- >> Delete Button
						{label: 'Delete', icon: 'delete', onclick: function() { 
							var oSel = $('#datagrid').datagrid('getSelected'); 
							if (oSel == null) { 
								$.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
							} else { 
								deleteData(['kode_mitra']);
							} 
						}}];
		setAction(buttons);
		
		
		$('#fm_search').focusFirst();
	});
//--><!]]></script>

<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
        	<table class="tb_form" style="margin-bottom:0px">
            <tr>
            	<td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
                </td>
            </tr>
            </table>
        </form>
    </div>
</div>
<div id="datagrid" toolbar="#tb"></div>